package com.lanou3g.bookstore.book.service;

import com.lanou3g.bookstore.book.dao.BookDao;
import com.lanou3g.bookstore.book.domain.Book;
import com.lanou3g.bookstore.util.util.JDBCUtil;

import java.util.List;

public class BookService {
    private BookDao bookDao = new BookDao();

    //查询所有图书
    public List<Book> findAll() {
        try {
            JDBCUtil.begin();
            List<Book> books = bookDao.findAll();
            return books;
        } finally {
            JDBCUtil.closeConn();
        }
    }

    public List<Book> findByCategory(int cid) {
        try {
            JDBCUtil.begin();
            List<Book> books = bookDao.findByCategory(cid);
            return books;
        } finally {
            JDBCUtil.closeConn();
        }
    }

    public Book load(String bid) {
        try {
            JDBCUtil.begin();
            Book book = bookDao.load(bid);
            return book;
        } finally {
            JDBCUtil.closeConn();
        }
    }

    //添加图书
    public void add(Book book) {
        try {
            JDBCUtil.begin();
            bookDao.add(book);
        } finally {
            JDBCUtil.closeConn();
        }
    }

    public void del(String bid) {
        bookDao.del(bid);
    }

    public void mod(Book book) {
        bookDao.mod(book);
    }
}
